package com.ruoyi.web.controller.used;

import java.util.List;

import com.ruoyi.used.domain.UsedAutonym;
import com.ruoyi.used.domain.UsedUser;
import com.ruoyi.used.service.IUsedAutonymService;
import com.ruoyi.used.service.IUsedUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实名认证Controller
 * 
 * @author ruoyi
 * @date 2020-07-09
 */
@Controller
@RequestMapping("/used/autonym")
public class UsedAutonymController extends BaseController
{
    private String prefix = "used/autonym";

    @Autowired
    private IUsedAutonymService usedAutonymService;

    @Autowired
    private IUsedUserService usedUserService;

    @RequiresPermissions("used:autonym:view")
    @GetMapping()
    public String autonym()
    {
        return prefix + "/autonym";
    }

    /**
     * 查询实名认证列表
     */
    @RequiresPermissions("used:autonym:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UsedAutonym usedAutonym)
    {
        startPage();
        List<UsedAutonym> list = usedAutonymService.selectUsedAutonymList(usedAutonym);
        return getDataTable(list);
    }

    /**
     * 导出实名认证列表
     */
    @RequiresPermissions("used:autonym:export")
    @Log(title = "实名认证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UsedAutonym usedAutonym)
    {
        List<UsedAutonym> list = usedAutonymService.selectUsedAutonymList(usedAutonym);
        ExcelUtil<UsedAutonym> util = new ExcelUtil<UsedAutonym>(UsedAutonym.class);
        return util.exportExcel(list, "autonym");
    }

    /**
     * 新增实名认证
     */
    @GetMapping("/add")
    public String add(ModelMap map, UsedUser user)
    {
        //下拉框选择用户
        List<UsedUser> userData =usedUserService.selectUsedUserList(user);
        map.put("user",userData);
        return prefix + "/add";
    }

    /**
     * 新增保存实名认证
     */
    @RequiresPermissions("used:autonym:add")
    @Log(title = "实名认证", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UsedAutonym usedAutonym)
    {
        return toAjax(usedAutonymService.insertUsedAutonym(usedAutonym));
    }

    /**
     * 修改实名认证
     */
    @GetMapping("/edit/{auId}")
    public String edit(@PathVariable("auId") Long auId, ModelMap mmap,UsedUser user)
    {
        UsedAutonym usedAutonym = usedAutonymService.selectUsedAutonymById(auId);
        mmap.put("usedAutonym", usedAutonym);

        //修改时的下拉框
        List<UsedUser> userData = usedUserService.selectUsedUserList(user);
        mmap.put("user",userData);
        return prefix + "/edit";
    }

    /**
     * 修改保存实名认证
     */
    @RequiresPermissions("used:autonym:edit")
    @Log(title = "实名认证", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UsedAutonym usedAutonym)
    {
        return toAjax(usedAutonymService.updateUsedAutonym(usedAutonym));
    }

    /**
     * 删除实名认证
     */
    @RequiresPermissions("used:autonym:remove")
    @Log(title = "实名认证", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(usedAutonymService.deleteUsedAutonymByIds(ids));
    }
}
